package com.nineclock.attendance.controller;

import com.nineclock.api.attendance.AttendPunchControllerApi;
import com.nineclock.attendance.dto.AttendPunchDTO;
import com.nineclock.attendance.dto.AttendPunchUserWholeDayDTO;
import com.nineclock.attendance.service.AttendPunchService;
import com.nineclock.common.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
public class AttendPunchController implements AttendPunchControllerApi {

    @Autowired
    private AttendPunchService attendPunchService;

    @Override
    @PostMapping("/punch")
    public Result punch(@RequestBody AttendPunchDTO punchDTO) {
        attendPunchService.punch(punchDTO);
        return Result.success();
    }


    @Override
    @GetMapping("/get")
    public Result<AttendPunchUserWholeDayDTO> getPunchData() {
        AttendPunchUserWholeDayDTO wholeDayDTO = attendPunchService.getPunchData();
        return Result.success(wholeDayDTO);
    }


    @Override
    @GetMapping("/members")
    public Result<List<AttendPunchDTO>> queryMembers(String startTime, String endTime) {
        List<AttendPunchDTO> list = attendPunchService.queryMembers(startTime, endTime);
        return Result.success(list);
    }


    @Override
    @GetMapping("/export")
    public void export(String startTime, String endTime) throws IOException {
        attendPunchService.export(startTime, endTime);
    }
}
